package study.chapter03.stream;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

//使用 BufferedReader 在控制台读取字符
public class TestBufferedReader {
    public static void main(String[] args) throws IOException {
        //读取字符
        //readChar();

        //读取一行
        readString();
    }

    //读取字符
    public static void readChar() throws IOException{
        char c;
        //在控制台输入字符存入到br
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        System.out.println("输入字符，按 'q' 键退出");
        //读取字符
        do {
            //一个字符地一个字符地读取
            c = (char)br.read();
            System.out.println(c);
        }while (c != 'q');
    }

    //读取字符串
    public static void readString() throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str;
        System.out.println("请输入一行字符，输入'end'退出");
        do {
            str = br.readLine();
            System.out.println(str);
        }while (!"end".equals(str));
    }
}
